/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import service.SanPhamService;

/**
 *
 * @author MongKieu
 */
public class TrangChuController extends AbstractController {

    private SanPhamService sanPhamService;

    public SanPhamService getSanPhamService() {
        return sanPhamService;
    }

    public void setSanPhamService(SanPhamService sanPhamService) {
        this.sanPhamService = sanPhamService;
    }

    public TrangChuController() {
    }

    @Override
    protected ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView("TrangChu");
        try {
            mv.addObject("message", "thanhcong");
            mv.addObject("listSanPham", sanPhamService.listAllSanPhamTrongNhaSach(0, 9));
        } catch (Exception e) {
            mv = new ModelAndView("ThongBaoLoi");
            mv.addObject("messageError", "Xin chào bạn, thông tin tìm kiếm không hợp lệ.");
        }
        return mv;
    }
}
